﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btuJiSuan_Click(object sender, EventArgs e)
        {
            try
            {
                double chang = Convert.ToDouble(txtChang.Text);
                double kuan = Convert.ToDouble(txtKuan.Text);
                double mianji = chang * kuan;
                labJieGuo.Text = mianji.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("计算时发生错误:"+ex.Message);
            }
        }

        private void btuJia_Click(object sender, EventArgs e) 
        {
            int number1, number2;
            if (!int.TryParse(txtNumber1.Text, out number1))
            {
                MessageBox.Show("输入的第一个数有问题！");
                txtNumber1.Focus(); //获得焦点
                txtNumber1.SelectAll(); //选中所有文本
                return;
            }
             
            if (!int.TryParse(txtNumber2.Text, out number2))
            {
                MessageBox.Show("输入的第二个数有问题！");
                txtNumber2.Focus();  //获得焦点
                txtNumber2.SelectAll(); //选中所有文本
                return;
            }

            int sum = number1 + number2;
            labJia.Text = sum.ToString();

        }

        private void txtNumber1_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox teBox = sender as TextBox;  //sender 里面存的是触发当前事件的控件

            
        }
    }
}
